$(function () {
    console.log(123);
    getInfo()



    $('#logout').on('click', function () {
        console.log('退出');
        layer.confirm('确认退出?', function (index) {
            localStorage.removeItem('u_token')
            location.href = './login.html'
            layer.close(index);
        });

    })


})

/* 全局函数 */
function render(u_info) {
    var data = u_info.nickname ? u_info.nickname : u_info.username
    $('#welcome').html(`欢迎你 ${data}`)
    if (u_info.user_pic !== null) {
        $('.layui-nav-img').prop('src', u_info.user_pic).show()
        $('.text-avatar').hide()
    } else {
        $('.layui-nav-img').hide()
        $('.text-avatar').html(data[0].toUpperCase()).show()
    }

}

function getInfo() {
    $.ajax({
        type: 'get',
        url: '/my/userinfo',
        success(res) {
            if (res.status !== 0) {
                return layui.layer.msg(res.message, {
                    icon: 5
                })

            }
            console.log(res);
            render(res.data)
        }
    })
}